Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

346
Visualizações
TypeError: Exception encountered when calling layer "conv1d" (type Conv1D)

I am working on a project "News Classification". Where the model has to classify(multi-class classification problem) a given text into business, entertainment, politics, sport and tech.

I am using TensorFlow==2.7.0 on Google Colab. I had trained 7 different models. After, training and made prediction on it. When compared to all models, Conv1d performed the best. The best performing model saved model_2.save('saved_model/my_model').It has done well till here.

But, When I want to load the saved model using the code

loaded_model = tf.keras.models.load_model('saved_model/my_model') then, I am getting the below exception:

TypeError                                 Traceback (most recent call last)
<ipython-input-129-c92edaf0db7f> in <module>()
----> 1 load_model = tf.keras.models.load_model('saved_model/my_model')
      2 # load_model.preditct(val_sentences)

1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape, allow_broadcast)
    547       str_values = [compat.as_bytes(x) for x in proto_values]
    548     except TypeError:
--> 549       raise TypeError(f"Failed to convert elements of {values} to Tensor. "
    550                       "Consider casting elements to a supported type. See "
    551                       "https://www.tensorflow.org/api_docs/python/tf/dtypes "

TypeError: Exception encountered when calling layer "conv1d" (type Conv1D).

Failed to convert elements of tf.RaggedTensor(values=tf.RaggedTensor(values=Tensor("Placeholder:0", shape=(None, 128), dtype=float32), row_splits=Tensor("Placeholder_1:0", shape=(None,), dtype=int64)), row_splits=Tensor("conv1d/Conv1D/RaggedExpandDims/RaggedFromUniformRowLength/RowPartitionFromUniformRowLength/mul:0", shape=(None,), dtype=int64)) to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.

Call arguments received:
  • inputs=tf.RaggedTensor(values=Tensor("Placeholder:0", shape=(None, 128), dtype=float32), row_splits=Tensor("Placeholder_1:0", shape=(None,), dtype=int64))

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It looks like you need to add .h5 on the file name. You need to add .h5 to the end of your file name. Instead of:

model_2.save('saved_model/my_model') try

model_2.save('saved_model/my_model.h5')
#Notice the .h5 -------------------^

You will also nee to change loaded_model = tf.keras.models.load_model('saved_model/my_model') to loaded_model = tf.keras.models.load_model('saved_model/my_model.h5')

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda